package com.training.persistence.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class GenericDaoImpl <T>
implements GenericDao<T>{

	private Class<T> type;

	@Autowired
	private SessionFactory sessionFactory;
	
    public GenericDaoImpl(Class<T> type) {
        this.type = type;
    }

    @SuppressWarnings("unchecked")
	public T create(T o) {
        return (T) getSession().save(o);
    }

    public void update(T o) {
        getSession().update(o);
    }

    public void delete(T o) {
        getSession().delete(o);
    }
    
    public Session getSession(){
    	return sessionFactory.getCurrentSession();
    }
    
}
